package nameless.aistudy.common.constant.path;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.stream.Stream;

import static nameless.aistudy.common.constant.path.DispatchPathConstants.AUTH_UNAUTHORIZED_PATH;


@Component
public class PublicPathConstants {

    public static final String[] PUBLIC_PATHS = {
            "/user/send-code",
            "/user/register",
            "/user/login",
            AUTH_UNAUTHORIZED_PATH
    };
    private static String[] PUBLIC_PREFIXES;
    private static String[] PUBLIC_PATHS_PATTERNS;

    public String[] getPublicPaths() {return PUBLIC_PATHS;}
    public String[] getPublicPrefixes() {return PUBLIC_PREFIXES;}
    public String[] getPublicPathsPatterns() {return PUBLIC_PATHS_PATTERNS;}



    public PublicPathConstants(
            @Value("${springdoc.swagger-ui.path:/swagger-ui}") String swaggerUiPath,
            @Value("${springdoc.api-docs.path:/v3/api-docs}") String apiDocsPath
    ) {
        PUBLIC_PREFIXES = new String[] {
                swaggerUiPath,
                apiDocsPath
        };
        PUBLIC_PATHS_PATTERNS = Stream.concat(
                Arrays.stream(PUBLIC_PATHS),
                Arrays.stream(PUBLIC_PREFIXES).map(prefix -> prefix + "/**")
        ).toArray(String[]::new);
    }

}
